<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    (function(type ,fcn ,res){
        let obj = {}
        function subscription (type , fcn){
            obj[type] = (obj[type] ? obj[type] : [])
            obj[type].push( fcn )
        }
        function issue(type , res){
            // if(obj[type]){
            //     obj[type].forEach((item) => {
            //         item(res)
            //     })

            // }else{
            //     console.log('没有订阅者收到消息');
            // }
            obj[type]? obj[type].forEach((item)=>{item(res)}) : console.log('没有订阅者收到消息');
            // obj[type].forEach((item)=>{item(res)}) || console.log('没有订阅者收到消息');
            // console.log('没有订阅者收到消息') || obj[type].forEach((item)=>{item(res)});
        }
        window.subscription = {subscription}
        window.issue = {issue}
    })()

    subscription.subscription('严老师' , function(res){
        console.log('丽丽订阅的'+ res );
    })
    subscription.subscription('严老师' , function(res){
        console.log('李丽订阅的'+ res );
    })
    subscription.subscription('严老师' , function(res){
        console.log('莉莉订阅的'+ res );
    })
    subscription.subscription('严老师' , function(res){
        console.log('呵呵订阅的'+ res );
    })
    subscription.subscription('严老师' , function(res){
        console.log('哈哈订阅的'+ res );
    })
    subscription.subscription('严老师' , function(res){
        console.log('哈哈订阅的'+ res );
    })
    subscription.subscription('严老师' , function(res){
        console.log('哈哈订阅的'+ res );
    })

    issue.issue('严老师' , '我峰哥真帅')
    issue.issue('艾老师' , '我峰哥真帅')
</script>